package com.lovo.frame;



import com.lovo.pojo.UserDO;
import com.lovo.service.UserService;
import com.lovo.service.impl.UserServiceImpl;
import com.lovo.util.GetConnectionUtil;
import com.lovo.util.Util;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Getjpanel extends JPanel implements ActionListener {

    private Icon sureimage = Util.getIcon("/images/buttonSure.jpg");
    private Icon offimage = Util.getIcon("/images/buttonOff.jpg");
    private JButton SurejButton;
    private JButton OffjButton;
    private Mainjframe frame;
    private JTextField textField1;
    private UserService userService = new UserServiceImpl();

    public Getjpanel(Mainjframe frame) {
        this.frame = frame;
        this.setLayout(null);
        this.setOpaque(false);

        JLabel jLabel = new JLabel("请输入取款金额：");
        jLabel.setForeground(Color.BLACK);
        jLabel.setFont(new Font("宋体",Font.BOLD,22));
        jLabel.setBounds(340, 420, 200, 40);
        this.add(jLabel);

        textField1 = new JTextField();
        textField1.setBounds(550, 420, 350, 40);
        this.add(textField1);

        SurejButton = new JButton(sureimage);
        SurejButton.setBounds(360, 500, 140, 50);
        this.add(SurejButton);
        SurejButton.addActionListener(this);

        OffjButton = new JButton(offimage);
        OffjButton.setBounds(700, 500, 140, 50);
        this.add(OffjButton);
        OffjButton.addActionListener(this);

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == SurejButton) {
            try {
                int id = frame.getLoginUser().getId();
                double a = Double.valueOf(textField1.getText());
                userService.getMoney(id, a);
                JOptionPane.showMessageDialog(this, "您本次取款" + a + "元");
                frame.switchPanel("menu");
            } catch (Exception exception) {
                JOptionPane.showMessageDialog(this, "您的余额不足");
            }
        } else if (e.getSource() == OffjButton) {
            frame.switchPanel("menu");
        }
    }
}
